<template>
  <div>
    <el-form-item label="图片宽度">
      <el-radio-group v-model="value.__config.widthUnit">
        <el-radio
          v-for="item in unitEnum"
          :key="item.code"
          :label="item.code"
          >{{ item.name }}</el-radio
        >
      </el-radio-group>

      <el-input-number
        size="small"
        style="width: 100%"
        v-model="value.__config.widthValue"
        controls-position="right"
        :min="0"
        :max="widthValueMax"
        :precision="0"
        :step="1"
        step-strictly
      ></el-input-number>
    </el-form-item>

    <el-form-item label="图片高度">
      <el-radio-group v-model="value.__config.heightUnit">
        <el-radio
          v-for="item in unitEnum"
          :key="item.code"
          :label="item.code"
          >{{ item.name }}</el-radio
        >
      </el-radio-group>

      <el-input-number
        size="small"
        style="width: 100%"
        v-model="value.__config.heightValue"
        controls-position="right"
        :min="0"
        :max="heightValueMax"
        :precision="0"
        :step="1"
        step-strictly
      ></el-input-number>
    </el-form-item>
  </div>
</template>

<script>
import basicmixins from "../basicmixins";
export default {
  name: "ImageMediaStyleProps",
  components: {
  },

  mixins: [basicmixins],

  data() {
    return {
      unitEnum: [
        { code: "%", name: "百分比" },
        { code: "px", name: "固定值" },
      ],
    };
  },

  computed: {
    widthValueMax() {
      return this.value.__config.widthUnit === "%" ? 100 : 9999;
    },
    heightValueMax() {
      return this.value.__config.heightUnit === "%" ? 100 : 9999;
    },
  },

  watch: {
    "value.__config.widthUnit"(value) {
      if (value === "%" && this.value.__config.widthValue > 100) {
        this.value.__config.widthValue = 100;
      }
    },
    "value.__config.heightUnit"(value) {
      if (value === "%" && this.value.__config.heightValue > 100) {
        this.value.__config.heightValue = 100;
      }
    },
  },

  methods: {},
};
</script>

<style lang="scss"></style>
